#!/usr/bin/python
# -*- encoding: utf-8 -*-
'''
@File    :   8.py
@Time    :   2020/05/04 21:50:30
@Author  :   Malygos_l 
@Version :   1.0
@Contact :   751756061@qq.com
@WebSite :   www.gitee.com/malygos_l
'''
# 京东二面笔试题
# 1） 生成一个大文件ip.txt,要求1200行，每行随机为172.25.254.1---172.25.254.254之间的一个ip地址;
# 2） 读取ip.txt文件统计这个文件中ip出现频率排前10的ip
# Start typing your code from here

from collections import Counter
from random import randint

def main():
    try:
        with open("homework4/ip.txt","w",encoding="UTF-8") as f:  #生成ip
            for i in range(1200):
                f.write("172.25.254."+str(randint(1,254))+"\n")

        with open("homework4/ip.txt","r",encoding="UTF-8") as f:  #获取频率前十的ip
            count = Counter(f.readlines())
            for x in range(10):
                print(list(count.keys())[x],end = "")
    except IOError as e:
        raise e
    
if __name__ == "__main__":
    main()